﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.TranslateApprove.Model;

public partial class System_TranslateApprove_FlowList : System.Web.UI.Page
{
    public LinkButton BtnDelete = null;
    protected void Page_Load(object sender, EventArgs e)
    {
       
        Bind();

    }

    private void Bind()
    {
        TableRow drw = new TableRow();
        TableCell cel = null;
        cel = new TableCell();
        cel.Text = "流程类型";
        cel.CssClass = "tabList";
        cel.Width = 120;
        cel.HorizontalAlign = HorizontalAlign.Center;
        drw.Cells.Add(cel);

        cel = new TableCell();
        cel.Text = "操作步骤";
        cel.CssClass = "tabstyle";
        cel.Width = 620;
        cel.HorizontalAlign = HorizontalAlign.Center;
        drw.Cells.Add(cel);

        cel = new TableCell();
        cel.Text = "删除";
        cel.CssClass = "tabstyle";
        cel.Width = 40;
        drw.Cells.Add(cel);

        TabList.Rows.Add(drw);
        List<Yipusoft.TranslateApprove.Model.KindInfo> list = Yipusoft.TranslateApprove.BLL.Kinds.GetList();
        bool Flag = false;
        foreach (KindInfo info in list)
        {
            if (info != null)
            {
                drw = new TableRow();
                cel = new TableCell();
                cel.CssClass = "tabstyle";
                cel.Text = info.KName+"：";
                cel.Width = 120;
                drw.Cells.Add(cel);
                cel = new TableCell();
                List<Yipusoft.TranslateApprove.Model.ProcessInfo> ListProcess = Yipusoft.TranslateApprove.BLL.Process.GetList("KID=" + info.Kind + "");
                if (ListProcess != null)
                {
                    foreach (Yipusoft.TranslateApprove.Model.ProcessInfo p in ListProcess)
                    {
                        if (cel.Text.Trim() != "")
                        {
                            cel.Text += "<font color=red>--></font>" + Yipusoft.TranslateApprove.BLL.JoinType.GetJoinType(p.JID).TypeName + "[" + Yipusoft.TranslateApprove.BLL.Roles.GetRoleInfo(p.RID).DutyName + "]";
                        }
                        else
                        {
                            cel.Text += Yipusoft.TranslateApprove.BLL.JoinType.GetJoinType(p.JID).TypeName + "[" + Yipusoft.TranslateApprove.BLL.Roles.GetRoleInfo(p.RID).DutyName + "]";    
                        }
                        Flag = true;
                        
                    }
                }
                cel.Wrap = true;
                cel.Width = 620;
                cel.CssClass = "tabstyle";
                drw.Cells.Add(cel);

                BtnDelete = new LinkButton();
                BtnDelete.Enabled = Flag;
                BtnDelete.CommandArgument = info.Kind.ToString();
                BtnDelete.Text = "删除";

                if (Flag)
                {
                    if (Yipusoft.TranslateApprove.BLL.SetupLog.GetCount("KID=" + info.Kind + "") <= 0)
                    {
                        BtnDelete.OnClientClick = " return confirm('确定删除此记录吗？')";
                        BtnDelete.Command += new CommandEventHandler(BtnDelete_Command);
                    }
                    else
                    {
                        BtnDelete.OnClientClick = " return alert('此流程已被使用，您不可以删除')";
                    }

                }

                
                cel = new TableCell();
                cel.Controls.Add(BtnDelete);
                cel.CssClass = "tabstyle";
                cel.Width = 40;

                drw.Cells.Add(cel);
                TabList.Rows.Add(drw);
            }
        }
    }

    public void BtnDelete_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;
        int Flag;
        if(int.TryParse(e.CommandArgument.ToString(),out Flag))
        {
            Yipusoft.TranslateApprove.BLL.Process.DeleteByKid(int.Parse(e.CommandArgument.ToString()));
            
        }
        Response.Redirect("FlowList.aspx");
        
    }

}
